package com.xiaojianone.product.controller;

import com.xiaojianone.product.bean.Product;
import com.xiaojianone.product.service.ProductService;
import jakarta.servlet.http.HttpServletRequest;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.concurrent.TimeUnit;

/**
 * ClassName  ProductController
 * Author  XiaojianOne
 * Date  2025/3/10 10:26
 * Version  8.0
 */

@RestController
@RequestMapping("/product")
public class ProductController {

    @Autowired
    private ProductService productService;

    /**
     * 查询商品
     * @param productId
     */
    @GetMapping("{id}")
    public Product getProduct(@PathVariable("id") Long productId,
                              HttpServletRequest request){
        String token = request.getHeader("X-Token");
        System.out.println("hello....token="+token);
        Product product = productService.getProductById(productId);

//        try {
//            TimeUnit.SECONDS.sleep(2);
//
//        } catch (InterruptedException e) {
//            throw new RuntimeException(e);
//        }

//        int num = 1/0;

        return product;
    }

}
